<script setup>
import {
  getBizUserInfo,
  addBizUserInfo,
  updateBizUserInfo,
  findMaxSort
} from "@/api/biz/bizUserInfo";
import OrderList from "../OrderList/index.vue";
import TixianList from "../TixianList/index.vue";
import AppointmentList from "../AppointmentOrder/index.vue";
const props = defineProps({
  id: {
    type: [Number, String],
    default: ""
  }
});

const formRef = ref();
const data = ref({
  loading: false,
  form: {
    id: props.id
  },
  activeName: "first"
});

onMounted(() => {
  if (data.value.form.id != "") {
    getInfo();
  }
});

function save() {
  updateBizUserInfo(data.value.form).then((res) => {
    if (res.code == 200) {
      ElMessage.success({
        message: "修改成功！",
        center: true
      });
    }
  });
}

function getInfo() {
  data.value.loading = true;
  getBizUserInfo(props.id).then((res) => {
    data.value.loading = false;
    data.value.form = res.data;
  });
  data.value.loading = false;
}

defineExpose({
  submit(callback) {
    if (data.value.form.id == "") {
      formRef.value.validate((valid) => {
        if (valid) {
          addUser(data.value.form).then(() => {
            ElMessage.success({
              message: "保存成功",
              center: true
            });
            callback && callback();
          });
        }
      });
    } else {
      formRef.value.validate((valid) => {
        if (valid) {
          if (data.value.form.name) {
            data.value.form.isShiming = "1";
          }
          updateUser(data.value.form).then(() => {
            ElMessage.success({
              message: "修改成功",
              center: true
            });
            callback && callback();
          });
        }
      });
    }
  }
});
</script>

<template>
  <div v-loading="data.loading">
    <el-tabs v-model="data.activeName" @tab-click="handleClick">
      <el-tab-pane label="投递订单" name="first">
        <OrderList :id="data.form.id"></OrderList>
      </el-tab-pane>
      <el-tab-pane label="上门订单" name="second">
        <AppointmentList :id="data.form.id"></AppointmentList>
      </el-tab-pane>
      <el-tab-pane label="用户提现" name="three">
        <TixianList :id="data.form.id"></TixianList>
      </el-tab-pane>
      <el-tab-pane label="编辑用户" name="four">
        <el-form
          ref="formRef"
          :model="data.form"
          :rules="data.rules"
          label-width="120px"
          label-suffix=" "
          label-position="top"
          style="padding: 0 20px"
        >
          <el-row :gutter="30">
            <el-col :span="6">
              <el-form-item label="姓名" prop="name">
                <el-input placeholder="请输入姓名" v-model="data.form.name" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="电话" prop="phone">
                <el-input placeholder="请输入电话" v-model="data.form.phone" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="12">
              <el-form-item label="备注" prop="name">
                <el-input
                  type="textarea"
                  placeholder="请输入姓名"
                  v-model="data.form.remark"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="12" style="text-align: left">
              <el-button type="primary" @click="save"> 保存信息</el-button>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
